<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="test"></div>
  <div id="test1"></div>
  <div id="test2"></div>

  <script src="../js/react.development.js"></script>
  <script src="../js/react-dom.development.js"></script>
  <script src="../js/babel.min.js"></script>
  <!-- props限制 -->
  <script src="../js/prop-types.js"></script> 

  <script type="text/babel">
    class Person extends React.Component {

      // 构造器是否接收props，是否传递给super，取决于是否希望在构造器中通过this访问实例
      constructor (props) {
        super (props)
        console.log ('conustructor', this.props)
      }

      // 必要性限制
      static propTypes = {
      name: PropTypes.string.isRequired,
      age:PropTypes.number,
      gender: PropTypes.string,
    }
      // 默认值限制
      static defaultProps = {
      gender: 'female',
      age: 21
    }
      render() {
        const {name, age, gender} = this.props
        // props是只读的 不能修改this.props.name = 'jack'
        return (
          <ul>
            <li>姓名:{name}</li>
            <li>年龄:{age + 1}</li>
            <li>性别:{gender}</li>
          </ul>
        )
      }
    }

    

    ReactDOM.render (<Person name='tom' />, document.getElementById ('test'))


   
  </script>
</body>
</html>